<template>
  <div class="login">
    <div class="box">
      <div class="div">员工管理系统</div>
      <el-form
        :model="user"
        ref="user"
        class="demo-ruleForm"
      >
        <el-form-item
          prop="userName"
          :rules="[
            { required: true, message: '账号不能为空' },
          ]"
        >
          <el-input
            type="text"
            size="small"
            placeholder="请输入账号/员工ID"
            v-model="user.userName"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item
          prop="userPwd"
          :rules="[
            { required: true, message: '密码不能为空' },
          ]"
        >
          <el-input
            type="text"
            size="small"
            v-model="user.userPwd"
            placeholder="请输入密码"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="submitForm('user')"
            >提交</el-button
          >
          <el-button @click="resetForm('user')" size="small">重置</el-button>
        </el-form-item>
      </el-form>
      <div class="shi">
          <p>是否忘记密码？请联系管理员</p>
          <p>坐席电话:010-111000</p>
      </div>
    </div>
  </div>
</template>
<script>
import {login} from '../api/Login/login'
export default {
  data() {
    return {
      user: {
        userName: "",
        userPwd:''
      },
    };
  },
  created(){
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          login({userName:this.user.userName,userPwd:this.user.userPwd}).then(res => {
            console.log(res);
            if (res.status === 200) {
              this.$message.success(res.msg)
              localStorage.setItem('token',res.data)
               localStorage.setItem('user',this.user.userName)
              this.$router.push('/')
            }else{
              this.$message.error(res.msg)
            }
          },err => {
            console.log(err);
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
@import '../style/scss.scss';
.login{
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0.85;
background: linear-gradient(0deg, rgba(115,178,255,1) 0%,rgba(16,95,208,1) 100%);
    .box{
        width:400px;
        height:400px;
        background: white;
        border-radius: 10px ;
        box-sizing: border-box;
        padding: 30px;
        p{
            font-size: $padding;
        }
    }
}
.div{
  font-size: 28px;
  margin-bottom: 20px;
}
.shi{
  width: 100%;
  height: 50px;
  display: flex;
  flex-direction: column;
  font-size: 22px;
  justify-content: space-around;
}
</style>